package illustration;

import java.awt.Color;
import java.util.Vector;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.ui.ApplicationFrame;
import org.jfree.data.xy.XYSeriesCollection;

public class ROCGraph extends ApplicationFrame {

    /**
	 * 
	 */
	private static final long serialVersionUID = 8354498053299652275L;

	public ROCGraph(Vector<ROCEntry> entries) {

        super("ROC Curve");

        final XYDataset dataset = createDataset(entries);
        final JFreeChart chart = createChart(dataset);
        final ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new java.awt.Dimension(500, 350));
        setContentPane(chartPanel);

    }
    
    private XYDataset createDataset(Vector<ROCEntry> summary) {

        final XYSeriesCollection dataset = new XYSeriesCollection();
		final XYSeries series = new XYSeries("Naive Bayes");

        for(int j = 0; j < summary.size(); j++) {
        

                float y = (float) summary.get(j).getTruePositiveRate();
                float x = (float) summary.get(j).getFalsePositiveRate();
                series.add(x, y);
   
            

        }
        dataset.addSeries(series);


        return dataset;
        
    }
    
    private JFreeChart createChart(final XYDataset dataset) {
        
        final JFreeChart chart = ChartFactory.createXYLineChart(
            "ROC Graph",      
            "False Positives",
            "True Positives",                      
            dataset,                 
            PlotOrientation.VERTICAL,
            true,                     
            true,                     
            false                     
        );

        chart.setBackgroundPaint(Color.white);

        final XYPlot plot = chart.getXYPlot();
        plot.setBackgroundPaint(Color.lightGray);
        plot.setDomainGridlinePaint(Color.white);
        plot.setRangeGridlinePaint(Color.white);
        
        final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();

        plot.setRenderer(renderer);
                
        return chart;
        
    }
}
